import { ClientApi, ServerApi } from "../utils/Api";

const isClient = typeof window !== 'undefined';
class Sdk {
    getCreditOpinionData() { throw new Error("not implemented") }
}

function callApi(funcName, ...params) {
    let service = null;
    if (isClient) {
        service = new ClientServices();
    } else {
        service = new ServerServices();
    }
    return service[funcName](params);
}
class ApiSDK extends Sdk {
    constructor() {
        super();
        if (isClient) {
            this.sdk = new ClientServices();
        } else {
            this.sdk = new ServerServices();
        }
    }

    getCreditOpinionData(p1, p2) {
        return this.sdk.getCreditOpinionData(p1, p2);
    }
}
class ClientServices extends Sdk {
    getCreditOpinionData(...params) {
        return ClientApi.get("/getCreditOpinionData", );
    }
}

class ServerServices extends Sdk {
    getCreditOpinionData() {
        return ServerApi.get("/todo-list").then(res => {
            return res.data;
        });
    }
}

export { ApiSDK, ClientServices, ServerServices };